if(SERVER) then
	AddCSLuaFile("autorun/client/cl_userlist.lua")	
	function UserListSayRefresh(ply)
		local Users = ""
		local TableColor = "#66FF00"
		local tab, succ, err = gdatabase.Query("SELECT clients.name, servers.name FROM servers, clients WHERE clients.isonline = 1 AND clients.serverid = servers.id ORDER BY servers.name ASC", intDatabaseIndex)
		if(!succ) then
			Msg("**********************************************************\n")
			Msg("User List Error: "..err.."\n")
			Msg("**********************************************************\n")
		elseif(tab) then
			umsg.Start("UserListCheck", ply)
			umsg.String("<table border=\"0\" cellspacing=\"0\" align=\"center\" width=300\"><tr class=\"style1\"><th align=\"left\">Name</th><th align=\"right\">Server</th></tr>")
			umsg.End()
			
			for k,v in pairs(tab) do
				if(TableColor == "#FF9900") then
					TableColor = "#66FF00"
				else
					TableColor = "#FF9900"
				end
				umsg.Start("UserListCheck", ply)
				umsg.String("<tr class=\"style2\" bgcolor=\""..tablecolor .. "\"><td>"..v[1].."</td><td align=\"right\">"..v[2].."</tr>")
				umsg.End()
			end

			umsg.Start("UserListCheck", ply)
			umsg.String("</table>")
			umsg.End()
		else
			Msg("**********************************************************\n")
			Msg("User List Error?: Table is: "..tab.."\n")
			Msg("**********************************************************\n")			
		end
	end
	concommand.Add("Userlist", UserListSayRefresh)
	
	function UserListSay(ply, saywhat, teamsay)
		if(string.find(string.lower(saywhat), "!userlist") == 1) then
			UserListSayRefresh(ply)
		end
	end
	hook.Add("PlayerSay", "UserListSay", UserListSay)	
end
